
const redirectDetailPage = (orderId,orderType) => {
    let pathUrl = "";
    switch (Number(orderType)) {
        case 3:
            pathUrl = `/specialtySubPack/pages/orderDetail/specialtyOrderDetail?orderId=${orderId}`;
            break;
        default:
			pathUrl = '/ticketSubPack/pages/OrderCompleted/index';
            break;
    }
    console.log(pathUrl,'pathUrl')
    uni.navigateTo({
        url: pathUrl,
        success: (res) => {
            console.log(res,"nav-res")
        },
        fail: (err)=> {
            console.log(err,'nav-err')
        }
    })
};

const wxPay = (
    timeStamp,
    nonceStr,
    packageValue,
    signType,
    paySign,
    orderId,
    orderType
) => {
    console.log({timeStamp,
        nonceStr,
        packageValue,
        signType,
        paySign},"支付参数")
    return new Promise((resolve, reject) => {
        wx.requestPayment({
            orderInfo: undefined,
            provider: 'wxpay',
            timeStamp:timeStamp, // 注意大小写
            nonceStr,
            package: packageValue,
            signType,
            paySign,
            success(res) {
                console.log(res, '支付成功');
                redirectDetailPage(orderId,orderType);
                resolve(res);
            },
            fail(err) {
                console.log(err, 'pay-error-error-pay');
                uni.showModal({
                    title: '提示',
                    content: '支付失败',
                    showCancel: false,
                    success: () => {
                        console.log("支付失败");
                        redirectDetailPage(orderId,orderType);
                    }
                });
                reject(err);
            }
        });
    });
};

export default wxPay;
